<?php
	include_once("Database.inc");
	
class Province {
	
	public $id;
	public $name;
	
	public static function getAllProvinces() {
		$p = array();
		
		$query = $GLOBALS["DB"] -> doQuery("SELECT PROVINCECODE, PROVINCENAME FROM PROVINCES ORDER BY PROVINCECODE");
		
		while ($row = mssql_fetch_array($query)) {
			array_push($p, Province::getProvinceFromArray($row));
		}
		
		return $p;
	}
	
	public static function getProvince($id) {
		$query = $GLOBALS["DB"] -> doQuery("SELECT PROVINCECODE, PROVINCENAME FROM PROVINCES WHERE PROVINCECODE=$id");
		
		if ($row = mssql_fetch_array($query)) {
			return Province::getProvinceFromArray($row);
		} else {
			return null;
		}
	}
	
	protected static function getProvinceFromArray($array) {
		$p = new Province();
		
		$p->id = $array[0];
		$p->name = $array[1];
		
		return $p;
	}
}